<%--
 *  File:    ControlGLAccountSummary.jsp
 *  @Author: Stephen Liu
 *  Date:    Thursday, January 29, 2004

 *  Copyright (C) 2000 - 2001 Oval Technologies, Inc.
 *  All rights reserved.
 *
 *  This software is the confidential and proprietary information of Oval
 *  Technologies, Inc. ("Confidential Information").  You shall not
 *  disclose such Confidential Information and shall use it only in
 *  accordance with the terms of the license agreement you entered into
 *  with Oval.
--%>

<%@ page language="java" %>
<%@ page import="java.util.*" %>
<%@ page import="org.apache.log4j.Category" %>
<%@ page import="com.oval.util.*" %>

<%@ page contentType ="text/html;charset=UTF-8" %>
<%@ taglib uri="/WEB-INF/PageFlow.tld" prefix="PageFlow" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/custom.tld" prefix="custom" %>

<%
  Category cat = Category.getInstance("jsp.ControlGLAccountSummary");
  String strModuleName = "GL";
  String privilegeCode = "40108";
  String strTableName = "ovglaccountsummary";
%>

<%@ include file="/inc/PageDefault.inc" %>
<%@ include file="/inc/SessionTimeout.inc" %>
<%@ include file="/inc/Security.inc" %>
<%@include file="/inc/Print.inc"%>
<html>
<head>
<title>controlglaccountsummary</title>
<PageFlow:CheckPageFlow pageName="controlglaccountsummary"/>
<%@ include file="/inc/SumDiv.inc" %>
<%
  HashMap userinfo = (HashMap) session.getAttribute("userinfo");
  if (userinfo == null)
    userinfo = new HashMap();

  Vector glaccountsummary = (Vector) pageContext.getAttribute("glaccountsummary");
  if (glaccountsummary == null)
    glaccountsummary = new Vector();

  HashMap glinfo = (HashMap) pageContext.getAttribute("glinfo");
  if (glinfo == null)
    glinfo = new HashMap();

  String strClassType = "none";
%>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="../css/<%= strLanguageCode %>/main.css" type="text/css">
<script language="JavaScript" src="../css/<%= strLanguageCode %>/script.js"></script>
<script language="JavaScript" src="../js/ScriptLib.js"></script>
<script language="JavaScript" src="../js/SummaryDivision.js"></script>
<script language="JavaScript">
function page_summary(actionvalue, orderbyname)
{
  var editform = summaryPrepare(frm, actionvalue, orderbyname);
  editform.action = "ControlGLAccountSummary.jsp?<%= OvalTools.randomURL() %>&booksetid=" + frm.booksetid.value+"&booksettype=" + frm.booksettype.value;
  isRunning = true;
  editform.target = "_self";
  isRunning = true;
  editform.submit();
}

function page_radiotrue(idname, id, grade, flag, isbottom)
{
  radiotrue(idname);
  frm.glaccountid.value = id;
  frm.grade.value = grade;
  frm.createsubaccountflag.value = flag;
  frm.isbottom.value = isbottom;
}

function page_new() {
  var createtopaccountflag = "<%=JspHelper.filterNull( glinfo.get("createtopaccountflag") )%>";
  if (createtopaccountflag == "0") {
    alert("<%= message.getMessageDesc("CANNOT_CREATETOPACCOUNT") %>");
    return;
  }
  <% session.removeAttribute("glaccountid"); %>
  parent.location.href = "ControlGLAccountEditFrm.jsp?<%= OvalTools.randomURL() %>&glaccountlistid=" + frm.glaccountlistid.value + "&glaccountclasscode=" + frm.glaccountclasscode.value + "&booksetid=" + frm.booksetid.value +"&booksettype=" + frm.booksettype.value + "&entityid=" + frm.entityid.value + "&currencycode=<%=JspHelper.filterNull( glinfo.get("currencycode") )%>";
}

function page_newchild() {
  if (isEmpty(frm.glaccountid.value)) {
    alert("<%= message.getMessageDesc("PLEASE_SELECT") %>");
    return;
  }
  if (Number(frm.createsubaccountflag.value) == 0) {
    alert("<%= message.getMessageDesc("CANNOT_CREATESUBACCOUNT") %>");
    return;
  }
  if (frm.grade.value >= Number("<%=JspHelper.filterNull( glinfo.get("gradecount") )%>")) {
    alert("<%= message.getMessageDesc("GRADE_IS_MAX") %>");
    return;
  }
  parent.location.href = "ControlGLAccountEditFrm.jsp?<%= OvalTools.randomURL() %>&glaccountlistid=" + frm.glaccountlistid.value + "&glaccountclasscode=" + frm.glaccountclasscode.value + "&booksetid=" + frm.booksetid.value + "&booksettype=" + frm.booksettype.value + "&entityid=" + frm.entityid.value +  "&parentaccountid=" + frm.glaccountid.value + "&currencycode=<%=JspHelper.filterNull( glinfo.get("currencycode") )%>";
}

function page_edit() {
  if (isEmpty(frm.glaccountid.value)) {
    alert("<%= message.getMessageDesc("PLEASE_SELECT") %>");
    return;
  }
  parent.location.href = "ControlGLAccountEditFrm.jsp?<%= OvalTools.randomURL() %>&glaccountlistid=" + frm.glaccountlistid.value + "&glaccountid=" + frm.glaccountid.value+ "&booksetid=" + frm.booksetid.value + "&booksettype=" + frm.booksettype.value + "&entityid=" + frm.entityid.value;
}

function page_delete() {
  if (isEmpty(frm.glaccountid.value)) {
    alert("<%= message.getMessageDesc("PLEASE_SELECT") %>");
    return;
  }
  if (frm.isbottom.value == "0") {
    alert("<%= message.getMessageDesc("J_Onlyleaf_candelete") %>");
    return;
  }
  if(!confirm("<%= message.getMessageDesc("ARE_YOU_SURE_DEL") %>"))
    return;

  frm.actionname.value = "delete";
  frm.target = "_self";
  isRunning = true;
  frm.submit();
}

function page_automap(){
  frm.actionname.value = "automap";
  frm.target = "_self";
  isRunning = true;
  frm.submit();
}

function page_import()
{
  parent.location.href="../masterdata/spm/UploadEXL.jsp?<%= OvalTools.randomURL() %>&fromglurl=ControlGLAccountMgmtFrm.jsp&glaccountlistid=" + frm.glaccountlistid.value;
}

function page_export() {
  if(!confirm("<%= message.getMessageDesc("ARE_YOU_SURE") %>"))
  	return;

  frm.actionname.value = "excelprint";

  var print_params = new ActiveXObject("Scripting.Dictionary");
  print_params.add("glaccountlistid",frm.glaccountlistid.value);
  print_params.add("glaccountclasscode",frm.glaccountclasscode.value);
  print_params.add("searchname",frm.searchname.value);
  print_params.add("searchvalue",frm.searchvalue.value.replace("%","%25"));
  print_params.add("actionname",frm.actionname.value);
  print_params.add("pagename","controlglaccountsummary");

  var print_URL = mergeURL('<%=JspHelper.filterNull(realPrintPath)%>',print_params);
  //top.topFrame.PrintController.setCookieId('<%=JspHelper.filterNull( ExcelUtil.GetSessionID(session.getId()))%>');
	top.topFrame.PrintController.Print3(print_URL,"<%=JspHelper.filterNull(pageContext.getAttribute("glaccountlistid")!=null?"export_gllistaccount":"export_booksetaccount")%>","af_showreport");
}

function page_print() {
}
</script>
</head>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<form name="frm" method="post" action="../Dispatcher">
  <input type="hidden" name="pagename" value="controlglaccountsummary">
  <input type="hidden" name="actionname">

  <input type="hidden" name="glaccountid">
  <input type="hidden" name="grade">
  <input type="hidden" name="createsubaccountflag">
  <input type="hidden" name="isbottom">
  <custom:hidden property="glaccountlistid"/>
  <custom:hidden property="glaccountclasscode"/>
  <custom:hidden property="booksettype"/>
  <custom:hidden property="booksetid" name="glinfo" changedName="entityid"/>
  <custom:hidden property="booksetid"/>

  <table width="100%" cellspacing="0" cellpadding="0" border="0">
    <tr>
      <td>
        <table width="100%" border="0" cellspacing="0">
          <tr>
            <td class="summary_top" colspan="2"></td>
          </tr>
          <%@ include file="/inc/SummarySearch.inc" %>
        </table>
      </td>
    </tr>
    <tr>
      <td>
        <table width="100%" border="1" cellpadding="0" bordercolorlight="#999999" bordercolordark="#FFFFFF" cellspacing="0" align="center">
          <tr class="deepblue-left">
            <td width="22" class="title_center">&nbsp;</td>
            <td class="title_center" width="120"><a href="javascript:page_summary('orderby','accountcode')"><%= label.getLabelName("L_GLAccountCode") %></a></td>
            <td class="title_center"><a href="javascript:page_summary('orderby','accountname')"><%= label.getLabelName("L_GLAccountName") %></a></td>
            <td class="title_center" width="80"><a href="javascript:page_summary('orderby','quickcode')"><%= label.getLabelName("L_QuickCode") %></a></td>
            <td class="title_center" width="80"><a href="javascript:page_summary('orderby','fromtypename')"><%= label.getLabelName("L_FromType") %></a></td>
            <td class="title_center" width="80"><a href="javascript:page_summary('orderby','grade')"><%= label.getLabelName("L_Grade") %></a></td>
            <td class="title_center" width="40"><a href="javascript:page_summary('orderby','statusname')"><%= label.getLabelName("L_Status") %></a></td>
          </tr>
          <logic:iterate id="oneitem" collection="<%= glaccountsummary %>" indexId="idx">
          <%
            int i = idx.intValue();
            strClassType = (i % 2 == 1) ? "td-listrom" : "none";

            Integer grade = (Integer) ((HashMap) oneitem).get("grade");
            String space = "";
            if (grade != null)
              for(int j = 1; j < grade.intValue(); j ++)
                space += "&nbsp;&nbsp;";
          %>
          <tr onMouseOver="this.className='tr-over'" onMouseOut="this.className='<%=JspHelper.filterNull( strClassType )%>'" class="<%=JspHelper.filterNull( strClassType )%>" onClick="javascript:page_radiotrue('glaccountid<%=JspHelper.filterNull( i )%>','<custom:write name="oneitem" property="glaccountid"/>','<custom:write name="oneitem" property="grade"/>','<custom:write name="oneitem" property="createsubaccountflag"/>','<custom:write name="oneitem" property="isbottom"/>')">
            <td>
              <input type="radio" id="glaccountid<%=JspHelper.filterNull( i )%>" name="listid" value="<custom:write name="oneitem" property="glaccountid"/>" class="normalradio" <% if (i == 0) { %>checked<% } %>>
            </td>
            <td><%=JspHelper.filterNull( space )%>
              <a href="ControlGLAccountInfoFrm.jsp?<%= OvalTools.randomURL() %>&booksettype=<custom:write property="booksettype"/>&glaccountid=<custom:write name="oneitem" property="glaccountid"/>" target="_parent"><custom:write name="oneitem" property="accountcode"/></a>
            </td>
            <td><custom:write name="oneitem" property="accountname" nbsp="true"/></td>
            <td><custom:write name="oneitem" property="quickcode" nbsp="true"/></td>
            <td><custom:write name="oneitem" property="fromtypename" nbsp="true"/></td>
            <td><custom:write name="oneitem" property="grade"/></td>
            <td><custom:write name="oneitem" property="statusname"/></td>
          </tr>
          <% if (i == 0) { %>
          <script languagecode="javascript">page_radiotrue('glaccountid0','<custom:write name="oneitem" property="glaccountid"/>','<custom:write name="oneitem" property="grade"/>','<custom:write name="oneitem" property="createsubaccountflag"/>','<custom:write name="oneitem" property="isbottom"/>')</script>
          <% } %>
          </logic:iterate>
          <%@ include file="/inc/SummaryAction.inc" %>
        </table>
        <table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td class="summary_top"></td>
          </tr>
          <tr>
            <td class="td_center">
              <% if ((pageContext.getAttribute("glaccountlistid") != null && userinfo.get("grade") != null && userinfo.get("grade").toString().equals("1")) || (pageContext.getAttribute("ownerorgid") != null && pageContext.getAttribute("ownerorgid").equals(userinfo.get("orgid")))) { %>
              <% if ("1".equals(glinfo.get("createtopaccountflag"))) { %>
              <a onclick="page_new()"><custom:button type="1" label="L_New" imgsrc="new.gif" border="0" style="width:60"/></a>
    	      <% } if (glaccountsummary.size() > 0) { %>
              <a onclick="page_newchild()"><custom:button type="1" label="L_New-sub" imgsrc="new-sub.gif" border="0" style="width:60"/></a>
              <a onclick="page_edit()"><custom:button type="1" label="L_Edit" imgsrc="edit.gif" border="0" style="width:60"/></a>
              <a onclick="page_delete()"><custom:button type="1" label="L_Delete" imgsrc="delete.gif" border="0" style="width:60"/></a>
              <%if((pageContext.getAttribute("booksettype")!=null)&&("4".equals(pageContext.getAttribute("booksettype").toString()))){%>
              <a onclick="page_automap()"><custom:button type="1" label="L_Map" imgsrc="delete.gif" border="0" style="width:60"/></a>
              <%}
              } %>
              <a onclick="page_import()"><custom:button type="1" label="L_ImportGLAccount" border="0" style="width:80"/></a>
              <% } %>
              <% if (glaccountsummary.size() > 0) { %>
              <a onclick="page_export()"><custom:button type="1" label="L_ExportGLAccount" border="0" style="width:80"/></a>
              <!--a onclick="page_print()"><custom:button type="1" label="L_Print" imgsrc="print.gif" border="0" style="width:60"/></a-->
              <% } %>
            </td>
          </tr>
        </table>
      </td>
    </tr>
  </table>
</form>
</body>
</html>
